<template>
  <div>
    <el-button type="text" @click="toMyFund()">所有基金列表</el-button>
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="finfoWindcode" label="基金编码" width="180"></el-table-column>
      <el-table-column prop="finfoFullname" label="基金名称" width="180"></el-table-column>
      <el-table-column prop="finfoCorpFundmanagementcomp" label="基金管理人"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="150">
        <template slot-scope="scope">
          <el-button type="text" @click="fundDetail(scope.row.finfoWindcode)" siza="small">基金详情</el-button>
          <el-button type="primary" @click="addMyFund(scope.row.finfoWindcode)" size="small">添加为我的自选</el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  name: 'FundList',
  inject: ['reload'],
  data () {
    return {
      tableData: []
    }
  },
  mounted: function () {
    this.allfund()
  },
  methods: {
    allfund () {
      this.$axios.request('/fund/chinamutualfund/allfund', this.state, {withCredentials: true})
        .then((successResponse) => {
          this.bizresponse = successResponse.data
          if (successResponse.data.code === 0) {
            this.tableData = successResponse.data.data
            console.log(successResponse.data.data)
          } else {
            this.$message({
              type: 'error',
              message: this.bizresponse.message
            })
            if (successResponse.data.code === 5) {
              this.$router.replace({path: '/login'})
            }
          }
        })
    },
    addMyFund (finfoWindcode) {
      this.$axios
        .post('/fund/chinamutualfund/addmyfund', {
          finfoWindcode: finfoWindcode
        }).then((successResponse) => {
          if (successResponse.data.code === 0) {
            this.$message({
              type: 'success',
              message: '添加成功'
            })
          }
        }, (error) => {
          this.$message({
            type: 'error',
            message: '添加失败' + error.message
          })
        })
    },
    toMyFund () {
      this.$router.replace({path: '/myFundList'})
    }
  }
}
</script>

<style scoped>
</style>
